package com.itzxx.huazhun.ui.record.local

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.itzxx.huazhun.data.dao.CollectionEntity
import com.itzxx.huazhun.databinding.ItemRecordBinding
import com.itzxx.huazhun.data.model.RecordChildBean
import com.itzxx.huazhun.databinding.ItemRecordLocalBinding

/**
 * Desc:
 *
 * Author: zhangxiaoxiao
 * Date: 2024/7/4 10:42
 * Updater:
 * Update Time:
 * Update Comments:
 */
class RecordLocalAdapter : BaseQuickAdapter<CollectionEntity, RecordLocalAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: ItemRecordLocalBinding = ItemRecordLocalBinding.inflate(LayoutInflater.from(parent.context), parent, false),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: CollectionEntity?) {
        holder.binding.dataBean = item
        holder.binding.ckAgreement.setOnCheckedChangeListener { compoundButton, b ->
            item?.run {
                isCheck = b
            }
        }
    }

    fun removeItem(collectionEntity: CollectionEntity){
            for (i in 0..items.size-1){
                val  item = items[i]
                if (TextUtils.equals(item.probe_mac,collectionEntity.probe_mac)&&
                    TextUtils.equals(item.recordStartTime,collectionEntity.recordStartTime)){
//                    notifyItemRemoved(i)
                    removeAt(i)
                    return
                }
            }
    }
}